home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / usersdb / usersdb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  4.3 KB  |  178 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <clib/exec_protos.h>
  6. struct ConfBase
  7. {
  8.   char Handle[31];
  9.   ULONG NewSinceDate, ConfRead,ConfYM1;
  10.   ULONG Bytes_Download,Bytes_Upload;
  11.   ULONG Daily_Bytes_Limit,Daily_Bytes_Dld;
  12.   USHORT Upload,Downloads,RatioType,Ratio,Messages_Posted;
  13.   UWORD Access;
  14. };
  15. struct User {
  16.  char    Name[31],Pass[9],Location[30],PhoneNumber[13];
  17.  USHORT  Slot_Number;
  18.  USHORT  Sec_Status,
  19.      Sec_Board,                   /* File or Byte Ratio */
  20.      Sec_Library,                 /* Ratio              */
  21.      Sec_Bulletin,                /* Computer Type      */
  22.      Messages_Posted;
  23.  /* Note ConfYM = the last msg you actually read, ConfRead is the same ?? */
  24.  ULONG   NewSinceDate, ConfRead[9];
  25.  char    Conference_Access[10];
  26.  USHORT  Uploads, Downloads, ConfRJoin, Times_Called;
  27.  long    Time_Last_On, Time_Used, Time_Limit, Time_Total;
  28.  ULONG   Bytes_Download, Bytes_Upload, Daily_Bytes_Limit, Daily_Bytes_Dld;
  29.  char    Expert;
  30.  ULONG   ConfYM[9];
  31.  long    BeginLogCall;
  32.  UBYTE   Protocol, UUCPA, LineLength, New_User;
  33.  };
  34.  
  35. struct NewUser
  36. {
  37.    char Name[31];
  38.    char Handle[31];
  39.    char Pass[9];
  40.    char Group[31];
  41.    char PhoneNumber[13];
  42.    char Comment[4][41];
  43.    USHORT Slot_Number;
  44.    USHORT AccessLvl;
  45.    USHORT Area;
  46.    LONG Time_Last_On,Time_Used,Time_Limit,Time_Total;
  47.    char Expert;
  48.    UBYTE Protocol,UUCPA,LineLength, New_User;
  49.    USHORT ModuleAccess;
  50.    USHORT ScreenType;
  51.    USHORT ComputerType;
  52.    int Active;
  53.    int CpsUp;
  54.    int CpsDown;
  55.    LONG Baud;
  56. };
  57. char BBSLocal[200];
  58. char UserData[200];
  59. void InitNewDB(struct NewUser *nu);
  60. void ConvertDB(struct NewUser *nu,struct User *u);
  61. void sr(char *s);
  62. main(int argc,char *argv[])
  63. {
  64.    char temp[100];
  65.    char NameDB[100];
  66.    int totalrecords;
  67.    USHORT UserNum=0;
  68.    FILE *fi,*fo;
  69.    struct NewUser nu;
  70.    struct User u;
  71.    if(argc!=4)
  72.    {
  73.      printf("UsersDB version 1.0 written by Joseph Hodge\n");
  74.      printf("Usage: UsersDB <BBS location> <UserData location> <Records>\n");
  75.      printf("   ie: UsersDB BBS: BBS:User.Data 400 \n");
  76.      printf("\n");
  77.      exit(0);
  78.    }
  79.    strcpy(BBSLocal,argv[1]);
  80.    strcpy(UserData,argv[2]);
  81.    sr(BBSLocal);
  82.    sr(UserData);
  83.    strcpy(temp,argv[3]);
  84.    totalrecords=atoi(temp);
  85.    if(BBSLocal[strlen(BBSLocal)-1]!=':' && BBSLocal[strlen(BBSLocal)-1]!='/') strcat(BBSLocal,"/");
  86.    strcpy(NameDB,BBSLocal);
  87.    strcat(NameDB,"USER.DB"); 
  88.    fi=fopen(UserData,"rb");
  89.    if(fi==NULL)
  90.    {
  91.      printf("Error, Can't locate user.data\n");
  92.      exit(0);
  93.    }
  94.    fo=fopen(NameDB,"wb");
  95.    while(fread((APTR)&u,sizeof(struct User),1,fi)!=NULL)
  96.    {
  97.    
  98.      if(u.Slot_Number!=0)
  99.      {
  100.        nu.Slot_Number=UserNum;
  101.        ConvertDB(&nu,&u);
  102.        strcpy(nu.Name,nu.Handle);
  103.            fwrite((APTR)&nu,sizeof(struct NewUser),1,fo);
  104.        UserNum +=1;
  105.      }
  106.      
  107.    }
  108.    fclose(fi);
  109.    sprintf(NameDB,"%sUSER.KEY",BBSLocal);
  110.    fi=fopen(NameDB,"w");
  111.    fprintf(fi,"%d\n",UserNum);
  112.    fclose(fi);
  113.    InitNewDB(&nu);
  114.    while(UserNum<totalrecords)
  115.    {
  116.      nu.Slot_Number=UserNum;
  117.      fwrite((APTR)&nu,sizeof(struct NewUser),1,fo);
  118.      UserNum +=1;
  119.    }
  120.    fclose(fo);
  121.    exit(0);
  122.  
  123. void InitNewDB(struct NewUser *nu)
  124. {
  125.    strcpy(nu->Handle,"");
  126.    strcpy(nu->Pass,"");
  127.    strcpy(nu->Group,"");
  128.    strcpy(nu->PhoneNumber,"");
  129.    strcpy(nu->Comment[0],"");
  130.    strcpy(nu->Comment[1],"");
  131.    strcpy(nu->Comment[2],"");
  132.    nu->AccessLvl=0;
  133.    nu->Area=1;
  134.    nu->Time_Last_On=0;
  135.    nu->Time_Used=0;
  136.    nu->Time_Limit=0;
  137.    nu->Time_Total=0;
  138.    nu->Expert=0;
  139.    nu->ModuleAccess=0;
  140.    nu->ScreenType=0;
  141.    nu->ComputerType=0;
  142.    nu->Active=0;
  143. }
  144.  
  145. void ConvertDB(struct NewUser *nu,struct User *u)
  146. {
  147.    strcpy(nu->Handle,u->Name);
  148.    strcpy(nu->Pass,u->Pass);
  149.    strcpy(nu->Group,u->Location);
  150.    strcpy(nu->PhoneNumber,u->PhoneNumber);
  151.    strcpy(nu->Comment[0],"");
  152.    strcpy(nu->Comment[1],"");
  153.    strcpy(nu->Comment[2],"");
  154.    nu->AccessLvl=u->Sec_Status;
  155.    nu->Area=1;
  156.    nu->Time_Last_On=u->Time_Last_On;
  157.    nu->Time_Used=u->Time_Used;
  158.    nu->Time_Limit=u->Time_Limit;
  159.    nu->Time_Total=u->Time_Total;
  160.    nu->Expert=u->Expert;
  161.    nu->ModuleAccess=u->Sec_Status;
  162.    nu->ScreenType=0;
  163.    nu->ComputerType=u->Sec_Bulletin;
  164.    nu->Active=1;
  165. }
  166.  
  167. void sr(char *s)
  168. {
  169.    register int i;
  170.    i=strlen(s)-1;
  171.    while(i>-1)
  172.    {
  173.      if(*(s+i)<=32) *(s+i)='\0'; else break;
  174.      i--;
  175.    }
  176. }
  177.